package chapter_09_composite.classic;

/**
 * @author yaochenglong
 * @date 2017/10/19
 */
public class Client {
    public static void main(String[] args) {
        Branch root = new Branch();
        root.doSomething();

        Branch branch = new Branch();
        Leaf leaf = new Leaf();

        root.add(branch);
        branch.add(leaf);
    }
    //通过递归遍历树
    public static void display(Branch root){
        for(Component component : root.getChildren()){
            //叶子节点
            if(component instanceof Leaf){
                component.doSomething();

            //树枝节点
            }else{
                display((Branch) component);
            }
        }
    }
}
